
//
// 110603 - AH - (Garage) Created.
//

package org.soekrat.engine;

import java.util.StringTokenizer;

import org.soekrat.engine.util.StringMetric;

/**
 * <p>
 *   Base class for objects that tells if a 
 *   {@link String} matches a
 *   {@link SoekratName}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public abstract class SoekratNameMatcher 
{
  public abstract StringMetric getStringMetric();
  
  /**
   * <p>
   *   Matches.
   * </p>
   * @param s    {@link String} to match;
   * @param name {@link SoekratName} to match.
   * @return {@code true} if match, {@code false} if does not.
   */
  public abstract boolean match(String s, SoekratName name);
  
  /**
   * <p>
   *   Tokenize input to be matched.
   * </p>
   * @param s {@code String} to tokenize.
   * @return Tokens.
   */
  protected static String[] tokenize(String s)
  {
    StringTokenizer st=new StringTokenizer(s);
    int n=st.countTokens();
    String[] retVal=new String[n];
    
    for (int i=0; i<n; i++) retVal[i]=st.nextToken();
    
    return retVal;
  }
  
}
